export default class StringUtils {
  /** 判断字符串为空 */
  public static isBlank(str: string): boolean {
    return str == null || str.trim() === ''
  }

  /** trim特定字符串 */
  public static trimSpecificString(str: string, toRemove: string): string {
    str = StringUtils.trimBegin(str, toRemove)
    return StringUtils.trimEnd(str, toRemove)
  }

  /** trim字符串结尾 */
  public static trimEnd(str: string, removeLastStr: string): string {
    if (!str || !removeLastStr) {
      return str
    }
    while (str.endsWith(removeLastStr)) {
      str = str.substring(0, str.length - removeLastStr.length)
    }
    return str
  }

  /** trim字符串开头 */
  public static trimBegin(str: string, removeBeginStr: string): string {
    if (!str || !removeBeginStr) {
      return str
    }
    while (str.startsWith(removeBeginStr)) {
      str = str.substring(removeBeginStr.length)
    }
    return str
  }

  /** 字符串首字母变小写 */
  public static firstToLowerCase(input: string): string {
    if (!input) {
      return input
    }
    return input.charAt(0).toLowerCase() + input.substring(1)
  }
}
